package com.xbongbong.saas.service;

import com.xbongbong.paas.pojo.dto.FormDataDeleteBatchDTO;
import com.xbongbong.paas.pojo.dto.FormDataGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.pojo.vo.PaymentSheetFromBalanceListVO;
import com.xbongbong.paas.pojo.vo.PrePaymentBalanceListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.formdata.pojo.dto.FormDataDetailDTO;
import com.xbongbong.pro.formdata.pojo.vo.FormDataDetailVO;
import com.xbongbong.pro.formdata.pojo.vo.MobileFormCommonDetailVO;
import com.xbongbong.pro.paymentbalance.pojo.dto.PaymentSheetFromBalanceDTO;
import com.xbongbong.pro.paymentbalance.pojo.vo.PaymentSheetFromBalanceVO;
import com.xbongbong.pro.sheet.pojo.dto.SheetDeleteHandleRelateDTO;
import com.xbongbong.saas.domain.entity.PaymentBalanceEntity;
import com.xbongbong.saas.domain.entity.ext.PaymentSheetEntityExt;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 预收款余额处理业务
 * @author 梁鲁江
 * @version v1.0
 * @date 2019/11/7 16:10
 * @since v1.0
 */
public interface PaymentBalanceService {
    /**
     * 根据回款单操作预收款余额
     * @param paymentSheetEntityExt
     * @param distributorMark
     * @throws XbbException
     */
    void saveByPaymentSheet(PaymentSheetEntityExt paymentSheetEntityExt, Integer distributorMark)  throws XbbException;

    /**
     * 预收款余额列表
     * @param formDataListDTO
     * @return
     * @throws XbbException
     */
    PrePaymentBalanceListVO prepaymentBalanceList(FormDataListDTO formDataListDTO) throws XbbException;

    /**
     * 预收款余额APP列表
     * @param formDataListDTO
     * @return
     * @throws XbbException
     */
    ListAppVO prepaymentBalanceAppList(FormDataListDTO formDataListDTO) throws XbbException;
    /**
     * 移动端detail
     * @param formDataGetDTO
     * @return MobileFormCommonDetailVO
     * @throws XbbException
     */
    MobileFormCommonDetailVO getMoblieDetail(FormDataGetDTO formDataGetDTO) throws XbbException;
    /**
     * web端detail
     * @param formDataDetailDTO
     * @return FormDataDetailVO
     * @throws XbbException
     */
    FormDataDetailVO getWebDetail(FormDataDetailDTO formDataDetailDTO) throws XbbException;

    /**
     * 详情tab里的回款单列表（预收款，红冲预收款余额，预收款核销）
     * @param paymentSheetFromBalanceDTO
     * @return
     * @throws XbbException
     */
    PaymentSheetFromBalanceListVO paymentSheetFromBalanceList(PaymentSheetFromBalanceDTO paymentSheetFromBalanceDTO) throws XbbException;

    /**
     * 获取某个客户的余额
     * @param paymentSheetFromBalanceDTO
     * @return com.xbongbong.pro.paymentbalance.pojo.vo.PaymentSheetFromBalanceVO
     * @throws XbbException
     * @author zcp
     * @date 19/12/10 010 14:08
     * @update 19/12/10 010 14:08
     * @since v1.0
     * @version v1.0
     */
    PaymentSheetFromBalanceVO getByCustomerId(PaymentSheetFromBalanceDTO paymentSheetFromBalanceDTO) throws XbbException;

    /**
     * 在选择关联客户时展示的关联客户列表，查询到客户的可核销余额，目前是只支持查询客户的余额
     * @param formDataListVO
     * @param corpid
     * @throws XbbException
     */
    void getSupplementAmount(PaasFormDataEsListVO formDataListVO, String corpid) throws XbbException;

    /**
     * 删除回款单时，同步更新客户的余额。目前，有3种回款单类型删除会影响余额：
     * 预收款（无明细，且无关联合同、无关联应收款）：客户余额减少
     * 预收款核销、红冲预收款余额（可能有明细）：客户余额增加
     *
     * 因此，如果导致该客户余额小于0，则该客户对应的预收款类型的回款单不能删除（因只有预收款类型删除是对客户余额减少）
     *
     * @param corpid 公司id
     * @param errorTypeSet 不允许删除类型
     * @param errorDataSet 不允许删除数据
     * @param customerIdSet 客户id集合
     * @param prepaymentNoMap 客户id-预收款类型回款单编号list对应关系map，与sheetIdMap对应
     * @param prepaymentIdMap 客户id-预收款类型回款单id list对应关系map，与sheetNoMap对应
     * @param delIdList 要删除的回款单id集合（当某个客户因余额小于0而其关联的所有预收款类型的回款单不能被删除时，要把其对应的ids从该list移除）
     * @param sheetDeleteHandleRelateDTO 删除/批量删除回款单，更新其关联业务（客户、合同、应收款）dto
     * @return java.util.List<com.xbongbong.saas.domain.entity.PaymentBalanceEntity>
     * @throws XbbException
     * @author zcp
     * @date 19/12/7 007 20:56
     * @update 19/12/7 007 20:56
     * @since v1.0
     * @version v1.0
     */
    List<PaymentBalanceEntity> updatePaymentBalance4Del(String corpid, Set<String> errorTypeSet, Set<String> errorDataSet, Set<Long> customerIdSet, Map<Long, List<String>> prepaymentNoMap, Map<Long, List<Long>> prepaymentIdMap, List<Long> delIdList, SheetDeleteHandleRelateDTO sheetDeleteHandleRelateDTO) throws XbbException;

    /**
     * 删除预收款余额记录（保证余额=0才能删除）
     * @param idIn
     * @param corpid
     * @return
     */
    Integer deleteBatch(List<Long> idIn, String corpid) throws XbbException;
    /**
     * 回滚预收款余额(del的修改)
     * @param idIn
     * @param corpid
     * @throws XbbException
     */
    void updateRollback(List<Long> idIn, String corpid) throws XbbException;

    /**
     * 通过客户id回滚es：如果新增的预收款余额，则删除es；如果原是对原预收款余额修改，则读库同步至es
     * @param customerIdIn
     * @param corpid
     * @throws XbbException
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    void updateRollbackByCustomerId(Collection<Long> customerIdIn, String corpid) throws XbbException;

    /**
     *删除预收款，之所以不用deleteBatch，是因为在删除之前会有一些业务判断，为了不影响之前的业务，重新写一个方法，里面调用deleteBatch
     *
     * @param formDataDeleteBatchDTO
     */
    List<Long> deletePaymentBalanceBatch(FormDataDeleteBatchDTO formDataDeleteBatchDTO) throws XbbException;
}
